<?php
    session_start();
    include_once '../../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $Oid = $_REQUEST['Oid'];
    
    $Count = "SELECT COUNT(*) AS N,GETDATE() AS HORA FROM segimagenes WHERE hcnsolexa = '".$Oid."'";
    $res = $con -> query($Count);
    
    while($res2 = mssql_fetch_array($res)){
        $N = $res2['N'];
        $Hora = $res2['HORA'];
    }
    if($N == 0){
        $Insert= "INSERT INTO segimagenes(hcnsolexa,ExamenC,FechaExamenC,Usu_oidExa)VALUES('".$Oid."','1',GETDATE(),'".$_SESSION['usuario']."')";
        $con->query($Insert);
        print_r(json_encode(array('Hora'=>$Hora)));
    }
    else{
        $Update = "UPDATE segimagenes
                   SET ExamenC = '1',
                       FechaExamenC = GETDATE(),
                       Usu_oidExa = '".$_SESSION['usuario']."'
                   WHERE hcnsolexa = '".$Oid."'";
        $con -> query($Update);
        
        print_r(json_encode(array('Hora'=>$Hora)));
    }
    $con->cerrarConexion();
?>
